Skip to content

Conversation

Greeshmanth1
Copy link

I have updated the run time complexities for the "len()" methods.

Added time complexity for the '__len__()' method.
Added runtime complexity for the __len__() method.
@Greeshmanth1
Copy link
Author

Incorporating runtime complexities in the documentation for the len() method offers clear insight and dispels potential confusion among users. Unlike the traditional len() method, which operates in O(n) time complexity, this implementation achieves O(1). This distinction is crucial for understanding the efficiency of this code.

@Greeshmanth1 Greeshmanth1 changed the title Greeshmanth1 patch 1 Added comments Mar 8, 2024
@grantjenks
Copy link
Owner

Unlike the traditional len() method, which operates in O(n) time complexity
What are you referring to?

@Greeshmanth1
Copy link
Author

Greeshmanth1 commented Mar 10, 2024

Traditional len() method TC is O(n).

myList=[1,2,3,4,5,]
print(len(myList)) #Output --> 5

In the above example the len() have O(n) complexity, But in your implementation it's just O(1). So i have added the TC in comments, so it can be helpful to the users to mention it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants